Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
Convert String with Time Value "0:00" into decimal/double value?

I am attempting to retrieve data from a table and convert them to double values in order to graph them. column 0 is filled with time values in the format of "00:00" and column 1 is filled with decimal values.

With this code I seem to have properly retrieved the data and converted the contents on column 1 to double value, but do not know how to convert a String with time values into double values in order to represent number of hours:

int row = tableRadio.getRowCount();
    for (int r = 0; r  < row; r++) {
        double r2 = Double.parseDouble( tableModel.getValueAt(r, 0).toString() );
        double r3 = Double.parseDouble( tableModel.getValueAt(r, 1).toString() );
        series.add(r2, r3);
    }

I keep getting java.lang.NumberFormatException: For input string: "0:00" when attempting to graph this data, which from what I understand is because a colon can not be equated with a number value. But how can I get say, "00:21" to instead show up as "0.21" or something that I can use to graph my data? Any suggestions and examples are welcome.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Use SimpleDateFormat to parse() the time column and create a time series chart, as shown here. Use setDateFormatOverride() on the resulting DateAxis to format the time, as shown here. If necessary, you can change the DateFormatSymbols, as shown here.

over 4 years ago · Santiago Trujillo Relatório

0

So I got it working using @Dawood ibn Kareem's method. Here's the final code that worked for me:

    //get number of rows
    int row = tableRadio.getRowCount();
    for (int r = 0; r  < row; r++) {

        //get column0's values and convert to String
        String time = ( tableModel.getValueAt(r, 0).toString() );

        //split time into two arrays
        String[] timeSplit = time.split(":");

        //convert arrays to doubles 
        double hours = Double.parseDouble(timeSplit[0]);
        double min = Double.parseDouble(timeSplit[1]);

        //represent column0 values by number of hours
        double col0 = (min / 60) + hours;

        //get column1's values and convert to double
        double col1 = Double.parseDouble( tableModel.getValueAt(r, 1).toString() );

        //add values to series
        series.add(col0, col1);
    }//end of for loop`

Now all of the table values are converted to doubles and I have gotten them to graph successfully.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda